package tools.code.generator;

import tools.code.generator.service.FieldInfo;

import java.io.File;
import java.util.List;

import static tools.code.generator.utils.ModelCodeGeneratorUtils.*;

/**
 * 代码生成器，行程
 *
 * @author 沈东生
 */
public class TripEventDataGenerator {

    public static void main(String[] args) throws Exception {
        File baseDir = new File(".");
        System.out.println(baseDir.getAbsolutePath());
        File outHiveSqlDir = new File(baseDir, "files/hive/dataplatform/hive-sql");
        File outHiveSqlFile = new File(outHiveSqlDir, "create_trip_events.sql");
        File outParquetConvertFile = new File(baseDir, "opentsp-location-tripanalysis/opentsp-location-tripanalysis-common/src/main/java/com.navinfo.tripanalysis.common.arithmetic.convert/EventDataParquetConvert.java");
        File outMongoConvertFile = new File(baseDir, "opentsp-location-tripanalysis/opentsp-location-tripanalysis-common/src/main/java/com.navinfo.tripanalysis.common.arithmetic.convert/EventDataMongoConvert.java");
        File outHbaseConvertFile = new File(baseDir, "opentsp-location-tripanalysis/opentsp-location-tripanalysis-common/src/main/java/com.navinfo.tripanalysis.common.arithmetic.convert/EventDataHbaseConvert.java");
        String hiveTableName = "trip_events";
        String hiveTableComment = "驾驶行为分析事件数据";

        File pojoFilePath = new File(baseDir, "opentsp-location-tripanalysis/opentsp-location-tripanalysis-common/src/main/java/com.navinfo.tripanalysis.common.arithmetic.common/OuterEventData.java");
        File metaFilePath = new File(baseDir, "opentsp-location-tripanalysis/opentsp-location-tripanalysis-offline/src/test/resources/generator/TripEventData.csv");
        System.out.println(pojoFilePath.getAbsolutePath());

        File outDocDir = new File(baseDir, "files/doc/驾驶行为分析");
        File outDocFile = new File(outDocDir, "数据模型_事件.xlsx");

        List<FieldInfo> fieldInfos = getFieldInfos(metaFilePath);

        //生成hive table的sql语句
        generateHiveTableSql(outHiveSqlFile, hiveTableName, hiveTableComment, fieldInfos);
        //生成数据模型文档
        outDocFile(outDocFile, fieldInfos);
//        //生成写Parquet文件相关的column
        generateParquetConvert(outParquetConvertFile, fieldInfos);
        //生成读写mongo相关代码
        generateMongoConvert(outMongoConvertFile, fieldInfos);
        generateHbaseConvert(outHbaseConvertFile, fieldInfos);
        generatePojoFields(pojoFilePath, fieldInfos);

    }

}
